/*JedisUtil*/

package dice.sinanya.db.tools;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import static dice.sinanya.system.MessagesSystem.redisAddress;
/*jedis工具类*/

public final class JedisUtil {
    private static final JedisPool jedisPool;
    private static int maxtotal;
    private static int maxwaitmillis;
    private static String host;
    private static int port;

    /*创建连接池*/
    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(16);
        jedisPoolConfig.setMaxIdle(4);
        jedisPoolConfig.setMinIdle(1);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisPoolConfig.setTestOnReturn(true);
        jedisPoolConfig.setTestOnCreate(true);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(5);
        jedisPoolConfig.setMinEvictableIdleTimeMillis(5 * 1000);
//        if (SinaNya.systemType.equals(SystemType.MAC)) {
//            redisAddress = "r-2zekqjpsytdso7bxv5pd.redis.rds.aliyuncs.com";
//        }
        jedisPool = new JedisPool(jedisPoolConfig, redisAddress, 6379, 3000, "bFhcFyCRrfHB2KLPxThWBdbx");
    }


    private JedisUtil() {
    }

    /*获取jedis*/
    public static Jedis getJedis(int databaseId) {
        Jedis jedis = jedisPool.getResource();
        jedis.select(databaseId);
        return jedis;
    }

    /*关闭Jedis*/
    public static void closeJedis(Jedis jedis) {
        if (jedis != null) {
            jedis.close();
        }
    }
}